{% assign t = site.data.locales[page.lang][page.lang] %}
<!DOCTYPE html>
<html {% if page.direction == "rtl" %}dir="rtl" {% endif %}lang="{{ page.lang }}">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    {% if page.title %}
    <title>{{ page.title }} — {{ site.title }}</title>
    {% elsif t.subtitle %}
    {% if page.direction == "rtl" %}
    <title>{{ site.title }} — {{ t.subtitle }}</title>
    {% else %}
    <title>{{ t.subtitle }} — {{ t.subtitle }}</title>
    {% endif %}
    {% else %}
    <title>{{ site.title }}</title>
    {% endif %}
    {% seo title=false %}
    {% feed_meta %}
    <meta name="viewport" content="width=device-width">
    <link rel="icon" type="image/x-icon" href="/img/favicon.ico">
    <link rel="apple-touch-icon" href="/img/apple-touch-icon.png">
    <link rel="stylesheet" href="/css/screen.css" type="text/css" media="screen">
    <link rel="stylesheet" href="/css/pygments.css" type="text/css" media="screen">
    {% if site.url == "http://localhost:4000" %}
    <script src="https://github.com/Khan/tota11y/releases/download/0.1.3/tota11y.min.js"></script>
    {% endif %}
    <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-76679469-2', 'auto');
      ga('set', 'anonymizeIp', true);
      ga('send', 'pageview');

    </script>
    {% if site.data.locales %}
    {% assign locales = site.data.locales | sort %}
    {% for locale in locales %}
      {% assign lang = locale[0] %}
      {% if lang == "en" %}
      <link rel="alternate" hreflang="en" href="{{ site.url }}" />
      <link rel="alternate" hreflang="x-default" href="{{ site.url }}" />
      {% else %}
      <link rel="alternate" hreflang="{{ lang }}" href="{{ lang | prepend: '/index_' | prepend: site.url }}" />
      {% endif %}
    {% endfor %}
    {% endif %}
  </head>
  <body>
    <div id="wrap">
      <div id="header" class="{{ page.header-class }}">
        <img alt="Homebrew logo" src="/img/homebrew-256x256.png" width="128" height="128">
        <h1><a href="/">Homebrew</a></h1>
        {% if t.subtitle %}
        <p id="subtitle"><strong>{{ t.subtitle }}</strong></p>
        {% endif %}

        {% if page.lang %}
        <select id="language" onchange="loadLanguage(this.options[this.selectedIndex].value)">
          {% for locale in locales %}
            {% assign lang = locale[0] %}
            {% assign locale_name = locale[1][lang].locale_name %}
            {% if page.lang == lang %}
            <option value="{{ lang }}" selected="selected">{{ locale_name }}</option>
            {% else %}
            <option value="{{ lang }}">{{ locale_name }}</option>
            {% endif %}
          {% endfor %}
        </select>
        {% endif %}
      </div>

      {{ content }}

    </div>

    <a href="https://github.com/Homebrew/brew/"><img id="forkme" src="https://aral.github.io/fork-me-on-github-retina-ribbons/right-grey@2x.png" alt="Fork me on GitHub"></a>
    <script>
      function selectText(elem) {
        if (document.selection) {
            var range = document.body.createTextRange();
            range.moveToElementText(elem);
            range.select();
        } else if (window.getSelection) {
            var range = document.createRange();
            range.selectNode(elem);
            window.getSelection().addRange(range);
        }
      }

      function loadLanguage(lang) {
        if (lang === {{ page.lang | jsonify }}) {
            return;
        } else if (lang === "en") {
            window.location.assign("/");
        } else {
            window.location.assign("/index_" + lang);
        }
      }
    </script>
  </body>
</html>
